//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package xin.fallen.dao;

import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ToolBoxDao {
    private static ToolBoxDao dao = null;

    public static synchronized ToolBoxDao getInstance() {
        if(dao == null) {
            dao = new ToolBoxDao();
        }

        return dao;
    }

    public ToolBoxDao() {
    }

    public String stringToUnicode(String strText) throws Exception {
        String strRet = "";

        for(int i = 0; i < strText.length(); ++i) {
            char c = strText.charAt(i);
            String strHex = Integer.toHexString(c);
            if(c > 128) {
                strRet = strRet + "\\u" + strHex;
            } else {
                strRet = strRet + "\\u00" + strHex;
            }
        }

        return strRet;
    }

    public String unicodeToString(String hex) {
        int t = hex.length() / 6;
        StringBuilder str = new StringBuilder();

        for(int i = 0; i < t; ++i) {
            String s = hex.substring(i * 6, (i + 1) * 6);
            String s1 = s.substring(2, 4) + "00";
            String s2 = s.substring(4);
            int n = Integer.valueOf(s1, 16).intValue() + Integer.valueOf(s2, 16).intValue();
            char[] chars = Character.toChars(n);
            str.append(new String(chars));
        }

        return str.toString();
    }

    public String convertStrToUnicodeNoHead(String strText) {
        String strRet = "";

        try {
            for(int e = 0; e < strText.length(); ++e) {
                char c = strText.charAt(e);
                String strHex = Integer.toHexString(c);
                if(c > 128) {
                    strRet = strRet + strHex;
                } else {
                    strRet = strRet + "00" + strHex;
                }
            }
        } catch (Exception var7) {
            strRet = "";
        }

        return strRet;
    }

    public String convertUnicodeNoHeadToStr(String hex) {
        int t = hex.length() / 4;
        StringBuffer str = new StringBuffer();
        String s = "";
        String s1 = "";
        String s2 = "";

        try {
            for(int e = 0; e < t; ++e) {
                s = "\\u" + hex.substring(e * 4, (e + 1) * 4);
                s1 = s.substring(2, 4) + "00";
                s2 = s.substring(4);
                int n = Integer.valueOf(s1, 16).intValue() + Integer.valueOf(s2, 16).intValue();
                char[] chars = Character.toChars(n);
                str.append(new String(chars));
            }
        } catch (Exception var10) {
            return "";
        }

        return str.toString();
    }

    public String MD5(String s) {
        char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

        try {
            byte[] e = s.toUpperCase().getBytes();
            MessageDigest mdTemp = MessageDigest.getInstance("MD5");
            mdTemp.update(e);
            byte[] md = mdTemp.digest();
            int j = md.length;
            char[] str = new char[j * 2];
            int k = 0;

            for(int i = 0; i < j; ++i) {
                byte byte0 = md[i];
                str[k++] = hexDigits[byte0 >>> 4 & 15];
                str[k++] = hexDigits[byte0 & 15];
            }

            return new String(str);
        } catch (Exception var11) {
            return "ERROR";
        }
    }

    public String getCurrentDate() {
        String res = "2000-01-01";

        try {
            SimpleDateFormat e = new SimpleDateFormat("yyyy-MM-dd");
            res = e.format(new Date());
        } catch (Exception var3) {
            res = "2000-01-01";
        }

        return res;
    }

    public String getCurrentSimpleDate() {
        String res = "20000101";

        try {
            SimpleDateFormat e = new SimpleDateFormat("yyyyMMdd");
            res = e.format(new Date());
        } catch (Exception var3) {
            res = "20000101";
        }

        return res;
    }

    public boolean isIntegerString(String sValue) {
        if(sValue != null && sValue.length() != 0) {
            boolean res = true;
            byte[] bs = sValue.getBytes();
            byte[] var7 = bs;
            int var6 = bs.length;

            for(int var5 = 0; var5 < var6; ++var5) {
                byte b = var7[var5];
                if(b < 48 || b > 57) {
                    res = false;
                    break;
                }
            }

            return res;
        } else {
            return false;
        }
    }

    public String encodeString(String data) {
        if(data == null) {
            return "";
        } else {
            String res = "";

            try {
                res = URLEncoder.encode(data, "UTF-8");
            } catch (Exception var4) {
                res = "";
            }

            return res;
        }
    }

    public String decodeString(String data) {
        if(data == null) {
            return "";
        } else {
            String res = "";

            try {
                res = URLDecoder.decode(data, "UTF-8");
            } catch (Exception var4) {
                res = "";
            }

            return res;
        }
    }
}
